import {
  tradePanelAvailable,
  maxPurchasable,
} from "./displayInfor";
import { clickBuyOrSellBtn } from "./priceLimit.js";
import { marketBuyOrSell } from "./marketPrice.js";
// import { get } from "@/http/http.js";

let typeStocObserver = null;

export function typeStock() {
  if (typeStocObserver) typeStocObserver.disconnect();
  let previousValues = {
    type: null,
  };

  typeStocObserver = new MutationObserver(() => {
    const btnGroup = document.querySelector("#trading_dom > div > div.flex.items-center.mx-4.border-0.border-b-\\[0\\.5px\\].border-c-divider-2.border-solid.justify-between.gap-1 > div > div > div > div.trade-mode-tabs-item-container.ms-\\[-8px\\].gui-font-face.gui_89d60db1.gui_bf9f1ad3.gui_86ab82e9 > div > button[data-active='true']")
    let type = null;
    if (btnGroup) {
      type = btnGroup.getAttribute("data-value");
    }

    const hasChanged = type !== previousValues.type;

    if (type && hasChanged) {
      previousValues = {
        type,
      };
      console.log(previousValues, "preeeeeeeeeeeeee");

      inStock(previousValues.type);
    }
  });

  typeStocObserver.observe(document.body, {
    childList: true,
    subtree: true,
    attributes: true,
    characterData: true,
  });
}

import { stopByBuyOrSell } from "./stopByConditional.js";
import { stopByTimeBuyOrSell } from "./stopByTime.js";
import { icebergBuyOrSell } from "./iceberg.js";
import { loopOrderBuyOrSell } from "./loopOrder.js";
import { stopByTrailBuyOrSell } from "./stopByTrail.js";

function inStock(value) {
  console.log(value);

  // get("/data/basic/trading")
  //   .then((res) => {
  const { asset } =
    JSON.parse(localStorage.getItem('userInfo'))
  console.log(asset, 'aaassssssssssss');

  if (value == "limitPrice") {
    // priceInput(inStockPrice);
    tradePanelAvailable(asset, value);
    maxPurchasable(asset, value);
    clickBuyOrSellBtn();
  }

  if (value == "marketPrice") {
    tradePanelAvailable(asset, value);
    maxPurchasable(asset, value);
    marketBuyOrSell();
  }
  if (value == "stopByConditional") {
    // getEntrustePrice(entrustedPrice);
    tradePanelAvailable(asset, value);
    stopByBuyOrSell();
  }
  if (value == "stopByTime") {
    tradePanelAvailable(asset, value);
    stopByTimeBuyOrSell();
  }
  if (value == "iceberg") {
    tradePanelAvailable(asset, value);
    icebergBuyOrSell();
  }
  if (value == "loopOrder") {
    tradePanelAvailable(asset, value);
    loopOrderBuyOrSell();
  }
  if (value == "stopByTrail") {
    tradePanelAvailable(asset, value);
    stopByTrailBuyOrSell();
  }
  // }
  // )
  //   .catch((err) => {
  //     console.error("spotCurrentCommission Error fetching data:", err);
  //   });
}

import { language } from "@/content-scripts/locales";

export function property() {
  const userInfo = JSON.parse(localStorage.getItem('userInfo'))
  let interval = setInterval(() => {
    const text1 = document.querySelector("#trade-assets-container > div > div.flex.flex-col.gap-3.pt-4")
    console.log(text1, 'ttttttteeeeeeeeeeee');
    console.log(Number(localStorage.getItem('priceInput')), "Number(localStorage.getItem('priceInput'))Number(localStorage.getItem('priceInput'))");
    console.log(Number(userInfo.asset));
    console.log((Number(userInfo.asset) / Number(localStorage.getItem('priceInput'))).toFixed(6));


    if (text1 && Number(localStorage.getItem('priceInput')) != 0) {
      clearInterval(interval)

      text1.innerHTML = `<div class="assets-detail"><div class="assets-account-item"><div class="assets-item-left tr-flex tr-items-center"><span class="tr-text-c-text-1">${language.available}</span><div class="mantine-4wx3v5" dir="ltr">BTC</div></div><div class="tr-text-c-text-1 tr-text-body-s tr-font-medium">${(Number(userInfo.asset) / Number(localStorage.getItem('priceInput'))).toFixed(6)}</div></div><div class="assets-account-item"><div class="assets-item-left tr-flex tr-items-center"><span class="tr-text-c-text-1">${language.available}</span><div class="mantine-4wx3v5" dir="ltr">USDT</div></div><div class="tr-text-c-text-1 tr-text-body-s tr-font-medium">${Number(userInfo.asset).toFixed(2)}</div></div></div>`

    }
  }, 100)

}
